package _11_位运算;

public class _367_有效的完全平方数 {

    public static void main(String[] args) {

        _367_有效的完全平方数 v = new _367_有效的完全平方数();

        System.out.println(v.isPerfectSquare(5));

    }

    // 二分求解
    public boolean isPerfectSquare(int num) {
        int begin = 1;
        int end = num;

        while (begin <= end) {
            int mid = begin + (end - begin >> 1);
            int results = num / mid;
            if (results > mid) {
                begin = mid + 1;
            } else if (results < mid) {
                end = mid - 1;
            } else return mid * mid == num;
        }
        return false;
    }

}
